package metier;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;

import configuration.Constante;

import jdbc.Connexion;

import metier.jdbc.stage.CategorieStageJdbc;

public class Stage implements Comparable<Stage>{
	
		private Integer idStage;
		private String libelleStage;
		private Date dateDebut;
		private Date dateFin;
		private Integer idCategorie;
		private static int tri = Constante.TRI_STAGE_NOM;
		
		public Stage(Integer idStage, String libelleStage, Date dateDebut,
				Date dateFin, Integer idCategorie) {
			this.idStage = idStage;
			this.libelleStage = libelleStage;
			this.dateDebut = dateDebut;
			this.dateFin = dateFin;
			this.idCategorie = idCategorie;
		}
		
		public Integer getIdStage() {
			return idStage;
		}
		public void setIdStage(Integer idStage) {
			this.idStage = idStage;
		}
		public String getLibelleStage() {
			return libelleStage;
		}
		public void setLibelleStage(String libelleStage) {
			this.libelleStage = libelleStage;
		}
		public Date getDateDebut() {
			return dateDebut;
		}
		public void setDateDebut(Date dateDebut) {
			this.dateDebut = dateDebut;
		}
		public Date getDateFin() {
			return dateFin;
		}
		public void setDateFin(Date dateFin) {
			this.dateFin = dateFin;
		}
		public Integer getIdCategorie() {
			return idCategorie;
		}
		public void setIdCategorie(Integer idCategorie) {
			this.idCategorie = idCategorie;
		}

		/**
		 * @return
		 */
		public Vector<Object> getVector(){
			Vector<Object> vector = new Vector<Object>();
			SimpleDateFormat sdf = new SimpleDateFormat(Constante.FORMAT_DATE_SHORT);
			vector.add(this.getLibelleStage());
			vector.add(sdf.format(this.getDateDebut()));
			vector.add(sdf.format(this.getDateFin()));
			CategorieStage categorieStage = CategorieStageJdbc.rechercherById(Connexion.getConnexion(), this.getIdCategorie());
			if ( categorieStage != null ){
				vector.add(categorieStage.getLibelleCat());
			}else{
				vector.add("");
			}
			return vector;
		}
		
		/* (non-Javadoc)
		 * @see java.lang.Object#toString()
		 */
		@Override
		public String toString() {
			return libelleStage;
		}
		
		@Override
		public int compareTo(Stage stage) {
			// TODO Auto-generated method stub
			switch (tri) {
			case  Constante.TRI_STAGE_NOM: // comparer l'id
					return this.getLibelleStage().compareTo(stage.getLibelleStage());
			case Constante.TRI_STAGE_DATE_DEB://comparer le nom
				return this.getDateDebut().compareTo(stage.getDateDebut());
			}
			
			return 0;
		}

		/**
		 * @return the tri
		 */
		public static int getTri() {
			return tri;
		}

		/**
		 * @param tri the tri to set
		 */
		public static void setTri(int tri) {
			Stage.tri = tri;
		}

}
